<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('选择承运人')" />

<body>
<div class="layui-fluid larry-wrapper">
    <div class="layui-row layui-col-space30">
        <div class="layui-col-xs20">
            <section class="panel panel-padding">
                <form id="form1" class="layui-form layui-form-pane" action="">
                    <div>&nbsp;</div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">承运人</label>
                            <div class="layui-input-inline">
                              <select lay-ignore="lay-ignore" class="cyr" name="cyrid" style="width: 193px"></select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">承运车辆</label>
                            <div class="layui-input-inline">
                                <select lay-ignore="lay-ignore" class="cph" name="cyclid" style="width: 193px"></select>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="create">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                    <input type="hidden" th:value="${ids}" id="wmsLoadingDetailedList">
                </form>
            </section>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<script>
    $(function () {
        $('.cyr').select2({
            ajax: {
                url: '/zxsdwms/wmsloading/searchCyr',
                dataType: 'json',
                 type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        mc: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr= new Array();
                    if(data){
                        for (var i=0;i<data.length;i++){
                            arr.push({id:data[i].cyrid,text:data[i].cyrmc});
                        }
                    }
                    console.log(arr);
                    // Tranforms the top-level key of the response object from 'items' to 'results'
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询字段',
            allowClear: true
        });
        $('.cph').select2({

            ajax: {
                url: '/zxsdwms/wmsloading/searchCph',
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        cph: params.term,
                        cyrid:$('.cyr').val()
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr= new Array();
                    if(data){
                        for (var i=0;i<data.length;i++){
                            arr.push({id:data[i].cyclid,text:data[i].cycl});
                        }
                    }
                    console.log(arr);
                    // Tranforms the top-level key of the response object from 'items' to 'results'
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询字段',
            allowClear: true
        });

    });
    layui.use(['myform','zzpUtils','form','jquery'],function () {
        var form = layui.form,
            zzpUtils = layui.zzpUtils,
            $ = layui.jquery;

        form.on("submit(create)",function(data){
            var ids = [];
            var wmsLoadingDetailedList=[];
            var id=$("#wmsLoadingDetailedList").val();

            if(id.indexOf(',') != -1){
                ids=id.split(',');

                for (var i = 0; i < ids.length; i++) {
                    var object={
                        fyid:ids[i]
                    };
                    wmsLoadingDetailedList.push(object);
                }

            }else{
                var object={fyid:id};
                wmsLoadingDetailedList.push(object);
            }
            var cyrid=$('.cyr').val();
            var cyrmc=$('.cyr').text();
            var cycl=$('.cph').text();
            var query={
                cyrid:cyrid,
                cyrmc:cyrmc,
                cycl:cycl,
                wmsLoadingDetailedList:wmsLoadingDetailedList
            }
            zzpUtils.confirm("是否确认创建装车单",function(index){
                zzpUtils.action({
                    url:"/wmsloading/addLoading",
                    data: JSON.stringify(query),
                    success:function (data) {
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            top.layer.msg(data.title);
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr);
                    }
                })
            })
            return false;
        });
    });
</script>
</html>